/*
 *  Date: 2011-11-6 下午04:00:21
 *  Copyright (c) 2011 asiainfo-linkage
 */
package com.gjframe.example.dao.impl;

import com.gjframe.commen.db.Engine;
import com.gjframe.commen.db.model.Condition;
import com.gjframe.commen.db.model.Updater;
import com.gjframe.commen.db.provider.annotation.TxSupport;
import com.gjframe.commen.db.provider.helper.Pagination;
import com.gjframe.example.bean.BasePerson;
import com.gjframe.example.dao.PersonDAO;

public class PersonDAOImpl implements PersonDAO {

    private Engine engine;

    public BasePerson findById(Integer id) throws Exception {
        return engine.getBeanById(BasePerson.class, id);
    }

    public Pagination<BasePerson> findList(Condition condition, Integer pageNo, Integer pageSize) throws Exception {
        return engine.getBeanPaginationByClass(BasePerson.class, condition, pageNo, pageSize);
    }
    
    @TxSupport
    public int update(BasePerson person)throws Exception{
        Updater<BasePerson> updater = new Updater<BasePerson>(BasePerson.class,person);
        return engine.updateByUpdater(updater);
    }

    @TxSupport
    public Integer save(BasePerson person) throws Exception {
        return engine.save(BasePerson.class, person);
    }
    @TxSupport
    public int delete(Integer id)throws Exception{
        BasePerson bean = new BasePerson();
        bean.setId(id);
        return engine.remove(BasePerson.class, bean);
    }

    public void setEngine(Engine engine) {
        this.engine = engine;
    }

}
